import 'package:flutter/material.dart';
import 'package:necproject/utils/g.dart';

import 'home/home.dart';
import 'category/category.dart';
import 'news/news.dart';
import 'mine/mine.dart';

class IndexPage extends StatefulWidget {
  int currentIndex = 0;
  IndexPage({Key? key, int this.currentIndex = 0}) : super(key: key);

  @override
  _IndexPageState createState() => _IndexPageState();
}

class _IndexPageState extends State<IndexPage> {
  final List<BottomNavigationBarItem> bottomNavItems = [
    BottomNavigationBarItem(
      backgroundColor: Colors.blue,
      icon: Icon(Icons.home),
      label: G.t('home'),
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.green,
      icon: Icon(Icons.message),
      label: G.t('news'),
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.amber,
      icon: Icon(Icons.shopping_cart),
      label: G.t('cart'),
    ),
    BottomNavigationBarItem(
      backgroundColor: Colors.red,
      icon: Icon(Icons.person),
      label: G.t('mine'),
    ),

    // BottomNavigationBarItem(
    //   backgroundColor: Colors.blue,
    //   icon: Icon(Icons.home),
    //   label: 'home',
    // ),
    // BottomNavigationBarItem(
    //   backgroundColor: Colors.green,
    //   icon: Icon(Icons.message),
    //   label: 'news',
    // ),
    // BottomNavigationBarItem(
    //   backgroundColor: Colors.amber,
    //   icon: Icon(Icons.shopping_cart),
    //   label: 'cart',
    // ),
    // BottomNavigationBarItem(
    //   backgroundColor: Colors.red,
    //   icon: Icon(Icons.person),
    //   label: 'mine',
    // ),
  ];

  final pages = [
    Home(),
    News(),
    Category(),
    Mine(),
  ];

  // int currentIndex = 0;


  @override
  Widget build(BuildContext context) {
    return 
    Scaffold(
      appBar: AppBar(
        title: Text(bottomNavItems[widget.currentIndex].label.toString())
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: bottomNavItems,
        currentIndex: widget.currentIndex,
        type: BottomNavigationBarType.fixed,
        // type: BottomNavigationBarType.shifting,
        onTap: (index) {
          _changePage(index);
        }
      ),
      body: pages[widget.currentIndex],
    );
  }

  void _changePage(int index) {
    if (index != widget.currentIndex) {
      setState(() {
        widget.currentIndex = index;
      });
    }
  }
}
